<!-- 
  @name: 积分兑换
  @date: 2020.1.10
 -->
<template>
	<view class="content">
		<!-- 顶部菜单 -->
		<view class="menu">
			<view class="icon"></view>
			<text class="text">当前积分</text>
			<text class="text2">{{integral}}</text>
		</view>
		
		<!-- 现金券列表 -->
		<view class="ticket-list">
			<view
				class="card"
				v-for="(item, index) in lists"
				:key="item.cashId"
				:class="(index % 2 === 0) ? 'bor' : ''">
				<view class="info">
					<view class="i1">现金券</view>
					<view class="i2">
						<text class="icon">￥</text>
						<text class="amount">{{item.cashMoney}}</text>
					</view>
				</view>
				<view class="tip">{{item.cashName}}</view>
				<view class="point">
					<view class="left">
						<text class="num">{{item.integraAmount}}</text>
						<text class="t1">分</text>
					</view>
					<view class="right">
						<button class="btn" @tap="exchange(item, index)">兑换</button>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 兑换说明 -->
		<view class="notice">
			<view class="tip">
				<text class="dian"></text>
				<text class="t1">兑换说明</text>
				<text class="dian"></text>
			</view>
			<view class="msg">
				<text class="dian"></text>
				<view class="text">可用积分大于现金券兑换所需积分时，可直接兑换。</view>
			</view>
			<view class="msg">
				<text class="dian"></text>
				<view class="text">可用积分小于现金券兑换所需积分时，不可兑换。</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lists: [],  //现金券列表
			}
		},
		computed: {
			//积分总额
			integral() {
				return this.$store.state.integral;
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			//前往兑换
			exchange(item, index) {
				this.$store.commit('setTmpData', JSON.stringify(item));
				this.$navigateTo('./edetails');
			},
			//获取列表
			getList() {
				this.$http({
					url: this.$api.integralUrl + 'getcashlist'
				}).then(res => {
					this.lists = res;
				});
			}
		}
	}
</script>

<style lang="scss">
	/* 顶部菜单 */
	.menu {
		width: 750rpx;
		height: 90rpx;
		padding-left: 68rpx;
		padding-right: 68rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: $color-white;
		.icon {
			width: 51rpx;
			height: 52rpx;
			background-image: url('../static/wxImage/icon-integral.png');
		}
		.text {
			flex: 1;
			margin-left: 14rpx;
		}
		.text2 {
			margin-left: 14rpx;
			font-size: 40rpx;
			color: $color-text-primary;
			font-family: $font-family-num;
		}
	}
	
	/* 现金券列表 */
	.ticket-list {
		width: 750rpx;
		margin-top: $spacing-col;
		.card {
			display: inline-block;
			width: 375rpx;
			padding: 30rpx 67rpx;
			padding-right: 0;
			background-color: $color-white;
			border-bottom: 1rpx solid $color-list;
			.info {
				width: 240rpx;
				height: 140rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				background-image: url('http://img.etubang.com/group1/M00/00/40/rBCky14YKI2AQWIiAAAHTqYZgR8147.png');
				.i1,
				.i2 {
					color: $color-white;
				}
				.i2 {
					margin-top: 2rpx;
					.icon{
						font-size: 36rpx;
					}
					.amount {
						margin-left: 15rpx;
						font-size: 60rpx;
						font-family: $font-family-num;
					}
				}
			}
			.tip {
				margin-top: 30rpx;
				padding-right: 100rpx;
			}
			.point {
				margin-top: 20rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				.left {
					flex: 1;
					color: $color-text-primary;
					.num {
						font-size: 36rpx;
						font-family: $font-family-num;
					}
					.t1 {
						margin-left: 5rpx;
						font-size: 24rpx;
					}
				}
				.right {
					padding-right: 50rpx;
					.btn {
						width: 90rpx;
						height: 46rpx;
						line-height: 46rpx;
						font-size: 26rpx;
						color: $color-white;
						background-color: $color-primary;
					}
				}
			}
		}
		.card.bor {
			border-right: 1rpx solid $color-list;
		}
	}
	
	/* 兑换说明 */
	.notice {
		width: 750rpx;
		padding-top: 40rpx;
		padding-bottom: 125rpx;
		padding-left: 88rpx;
		padding-right: 88rpx;
		background-color: $color-white;
		.dian {
			display: inline-block;
			width: 12rpx;
			height: 12rpx;
			background-color: $color-grey;
			border-radius: $border-radius-circle;
		}
		.tip {
			width: 100%;
			margin-top: 50rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			.t1 {
				margin: 0 20rpx;
				font-size: 30rpx;
			}
		}
		.msg {
			width: 100%;
			margin-top: 40rpx;
			display: flex;
			flex-direction: row;
			.dian {
				margin-top: 6rpx;
			}
			.text {
				flex: 1;
				line-height: 50rpx;
				margin-top: -15rpx;
				margin-left: 23rpx;
				color: $color-grey-dark;
				font-size: 24rpx;
			}
		}
	}
</style>
